package cn.acac.yygh.user.controller.admin;

import cn.acac.yygh.model.user.UserInfo;
import cn.acac.yygh.result.R;
import cn.acac.yygh.user.service.UserInfoService;
import cn.acac.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/userInfo")
public class AdminUserController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 根据条件查询UserInfo的信息，并进行分页
     * @param pageNum
     * @param pageSize
     * @param userInfoQueryVo
     * @return
     */
    @GetMapping("/{pageNum}/{pageSize}")
    public R findPageAll(@PathVariable("pageNum")Integer pageNum,
                         @PathVariable("pageSize")Integer pageSize,
                         UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> page = userInfoService.findPageAll(pageNum,pageSize,userInfoQueryVo);
        return R.ok().setData("total",page.getTotal()).setData("list",page.getRecords());
    }

    /**
     * 根据用户的id修改用户的状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable Long id,@PathVariable Integer status){
        userInfoService.updateStatus(id,status);
        return R.ok();
    }

    /**
     * 根据id查询用户信息和用户下所有的就诊人信息
     * @param id
     * @return
     */
    @GetMapping("/showUserInfo/{id}")
    public R showUserInfo(@PathVariable Long id){
        Map<String,Object> userInfoMap = userInfoService.showUserInfo(id);
        return R.ok().setData(userInfoMap);
    }


    /**
     * 通过或者不通过用户的认证信息
     * @param id
     * @param authStatus
     * @return
     */
    @PutMapping("/auth/{id}/{authStatus}")
    public R updateAuthStatus(@PathVariable Long id,@PathVariable Integer authStatus){
        if(authStatus == 2 || authStatus == -1){
            UserInfo userInfo = new UserInfo();
            userInfo.setId(id);
            userInfo.setAuthStatus(authStatus);
            userInfoService.updateById(userInfo);
        }
        return R.ok();
    }
}
